<?php
			// Use the MiniXML library for easy XML editing
			require_once('minixml/minixml.inc.php');
			
			include "config.php";
			
			$path = $_GET["path"];
						 
			$result_image_id = mysql_query("SELECT * from images where file_path='$path'");
				while($row = mysql_fetch_array($result_image_id))
					{		//should ever only return one userid.
							$image_id = $row[id];							
					}				
			$result = mysql_query("SELECT * FROM annotations where image_id='$image_id'");
							
			//Make SQL result $row[file_path]
			while($row = mysql_fetch_array($result)){
				$string .=  $row[file_path].",";
			}
			$string = substr($string, 0, -1); //get rid of the tailing comma!
			$layerArray = split("," , $string);

			$layerData=array();
			for ($i=0; $i<count($layerArray);$i++){
				$parsedDoc = new MiniXMLDoc();
				$parsedDoc->fromFile($layerArray[$i]);
				$rootEl = $parsedDoc->getRoot();
				$layer =& $rootEl->getElement('g');
				//generate json	
				$comment=$layer->getElement('text')->getValue();
				$username=$layer->getElement('title')->getValue();
				$layerData['layers'][] = array('username' => $username,'comment' => $comment);
				
				$data=json_encode($layerData);				
			}
			echo $data;			
?>


	
